#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <windows.h>
#include <conio.h>
#define HEIGHT 29
#define WIDTH 110 

const int dir[4][2] = {         //数组第一个坐标为y坐标
    {-1,0},         //向上
    {0,1},          //向右
    {1,0},          //向下
    {0,-1}          //向左
};

typedef enum BlockType {
    EMPTY = 0,
    FOOD = 1,
    BOUND = 2,
}BlockType;

typedef enum Direction {
    UP = 0,
    RIGHT = 1,
    DOWN = 2,
    LEFT = 3,
}Direction;

typedef struct Map
{
    BlockType data[HEIGHT][WIDTH];
    bool hasFood;
}Map;

typedef struct Pos {
    int x;
    int y;
}Pos;

typedef struct Snake {
    Pos snake[HEIGHT * WIDTH];
    int snakeLength;
    Direction snakeDirection;
    int lastMoveTime;
    int moveFrequency;
}Snake;
/*系统函数 */
void hideCursor();
void hideCursor() {
    HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    CONSOLE_CURSOR_INFO curInfo = { 1,FALSE };
    SetConsoleCursorInfo(hOutput, &curInfo);
}
void drawUnit(Pos p,char unit[]);
void drawUnitXY(int x,int y,char unit[]);
void drawIntXY(int x,int y,int unit);
void drawXDU();
void drawUnit(Pos p,char unit[]){
    COORD coord;
    HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    coord.X = p.x + 1;      //绘制地图时有一圈边框，所以要加上偏移量1
    coord.Y = p.y + 1;
    SetConsoleCursorPosition(hOutput,coord);
    printf("%s",unit);
}

void drawUnitXY(int x,int y,char unit[]){
    COORD coord;
    HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    coord.X = x + 1;      //绘制地图时有一圈边框，所以要加上偏移量1
    coord.Y = y + 1;
    SetConsoleCursorPosition(hOutput,coord);
    printf("%s",unit);
}

void drawIntXY(int x,int y,int unit){
    COORD coord;
    HANDLE hOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    coord.X = x + 1;      //绘制地图时有一圈边框，所以要加上偏移量1
    coord.Y = y + 1;
    SetConsoleCursorPosition(hOutput,coord);
    printf("%d",unit);
}
void drawXDU(){
    drawUnitXY(4,1,"█");
    drawUnitXY(8,1,"█");
    drawUnitXY(5,2,"█");
    drawUnitXY(7,2,"█");
    drawUnitXY(6,3,"█");
    drawUnitXY(5,4,"█");
    drawUnitXY(7,4,"█");
    drawUnitXY(4,5,"█");
    drawUnitXY(8,5,"█");
    drawUnitXY(10,1,"█");
    drawUnitXY(11,1,"█");
    drawUnitXY(12,1,"█");
    drawUnitXY(10,2,"█");
    drawUnitXY(13,2,"█");
    drawUnitXY(10,3,"█");
    drawUnitXY(14,3,"█");
    drawUnitXY(10,4,"█");
    drawUnitXY(13,4,"█");
    drawUnitXY(10,5,"█");
    drawUnitXY(11,5,"█");
    drawUnitXY(12,5,"█");
    drawUnitXY(16,1,"█");
    drawUnitXY(20,1,"█");
    drawUnitXY(16,2,"█");
    drawUnitXY(20,2,"█");
    drawUnitXY(16,3,"█");
    drawUnitXY(20,3,"█");
    drawUnitXY(16,4,"█");
    drawUnitXY(20,4,"█");
    drawUnitXY(17,5,"█");
    drawUnitXY(18,5,"█");
    drawUnitXY(19,5,"█");
    drawUnitXY(4,7,"MADE BY:");
    drawUnitXY(4,8,"ZIHAN WANG");
    drawUnitXY(4,9,"JUNTONG ZHAO");
}
